unit UAddRec;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, EREdit, ComCtrls, ExtCtrls;

type
  TfrmAddRec = class(TForm)
    edtmoney: TEREdit;
    Label1: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    Bevel1: TBevel;
    ListView1: TListView;
    Button1: TButton;
    procedure ComboBox1Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
      Rect: TRect; State: TOwnerDrawState);
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmAddRec: TfrmAddRec;

implementation

{$R *.dfm}

procedure TfrmAddRec.ComboBox1Change(Sender: TObject);
begin

  if Assigned(ListView1.Selected) then
  begin
    if ComboBox1.ItemIndex = 0 then
    begin
      Label1.Caption := '充值金额';
      ListView1.Selected.SubItems[3] := '充值记录';
    end
    else
    begin
      Label1.Caption := '消费金额' ;
      ListView1.Selected.SubItems[3] := '消费记录';
    end;
    ListView1.Selected.SubItems[4] :=  IntToStr(ComboBox1.ItemIndex) ;
  end;
end;

procedure TfrmAddRec.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmAddRec := nil
end;

procedure TfrmAddRec.ListView1DrawItem(Sender: TCustomListView;
  Item: TListItem; Rect: TRect; State: TOwnerDrawState);
begin
  if Item.SubItems[4] = '-1' then
  begin
        ListView1.Canvas.Brush.Color:= clAqua;
       // Sender.Canvas.FillRect(Rect);
        //ListView1.DefaultDrawColumnCell(rect,datacol,column,state);
  end;
end;

procedure TfrmAddRec.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
  edtmoney.Text := Item.SubItems[0];
  DateTimePicker1.DateTime := StrToDatetime(item.SubItems[2]);
  DateTimePicker2.DateTime := StrToDatetime(item.SubItems[2]);
  ComboBox1.ItemIndex := StrToInt(Item.SubItems[4]);
end;

end.
